Skip to content

Addressing transform sort order with null values #4783

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 24, 2020

Conversation

oshikryu
Copy link
Contributor

@oshikryu oshikryu commented Apr 22, 2020

Updating sort function to handle null value case
Changing sort transform tests to include null value

This should fix the issue in #4784

Example working codepen:
https://codepen.io/oshikryu/pen/rNOjeZb

@oshikryu oshikryu force-pushed the sort-order-with-null branch from f997283 to 9a4d3ca Compare April 22, 2020 18:56
@archmoj archmoj added status: reviewable bug something broken labels Apr 22, 2020
@archmoj archmoj requested a review from antoinerg April 22, 2020 19:24
@archmoj archmoj added this to the v1.54.0 milestone Apr 22, 2020
@archmoj archmoj added the community community contribution label Apr 22, 2020
@archmoj archmoj requested a review from alexcjohnson April 22, 2020 19:26
} else if(b.v === null) {
return 1;
}
return d2c(a.v) - d2c(b.v);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @oshikryu - looking good, and your test additions are excellent!

I think we want to treat any sort of invalid data the same as null - which, after running through d2c, becomes BADNUM from src/constants/numerical. BADNUM is just undefined but for clarity and consistency we prefer to use the named constant.

So this would look something like:

var ac = d2c(a.v);
var bc = d2c(b.v);
if(ac === BADNUM) {
    return -1;
}
if(bc === BADNUM) {
    return 1;
}
return ac - bc;

Also I suppose this can be up for discussion, but in several other contexts (eg Dash DataTable) we sort null values always at the end - the idea being you want them out of the way where you mostly ignore them. Here you're sorting them as "extra negative", which puts them last when sorting descending, but FIRST when sorting ascending.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point about "extra negative" for BADNUM values. I added the reference to BADNUM in the sort and updated the tests

Changing sort transform tests to include check for BADNUM

Sort ascending has BADNUM last (not "extra negative" where BADNUM
is first)

Sort descending has BADNUM last
@oshikryu oshikryu force-pushed the sort-order-with-null branch from 9a4d3ca to d267337 Compare April 24, 2020 07:17
@oshikryu
Copy link
Contributor Author

I'm not really sure what downstream errors were produced with this change. I could use some guidance @alexcjohnson

Copy link
Collaborator

@alexcjohnson alexcjohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent, thanks for the change, this looks good to me! 💃 @archmoj please merge when you're ready.

I'm not really sure what downstream errors were produced with this change.

Were the tests failing before your force push? Don't worry about it, the tests have been a little bit flaky lately and sometimes need to be rerun. For future reference though we discourage force pushes in this repo once a PR is open, as it can confuse the review process.

@archmoj archmoj merged commit c82ad2e into plotly:master Apr 24, 2020
@oshikryu oshikryu deleted the sort-order-with-null branch April 24, 2020 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken community community contribution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants